Analysing the Gapminder dataset
Introduction
Hi Robert, here is my reproducible analysis concerning the Gapminder dataset!
Get data
The data are included in the gapminder library
library(gapminder)
head(gapminder)## country continent year lifeExp pop gdpPercap
## 1 Afghanistan Asia 1952 28.801 8425333 779.4453
## 2 Afghanistan Asia 1957 30.332 9240934 820.8530
## 3 Afghanistan Asia 1962 31.997 10267083 853.1007
## 4 Afghanistan Asia 1967 34.020 11537966 836.1971
## 5 Afghanistan Asia 1972 36.088 13079460 739.9811
## 6 Afghanistan Asia 1977 38.438 14880372 786.1134
We work on 2012 only:
data=subset(gapminder, year==2007)Make the plot
# Basic ggplot2 chart
library(ggplot2)
p=ggplot(data,
aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
geom_point()
# Made interactive with plotly
library(plotly)##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
ggplotly(p)